<?php
class SearchKeyService extends BaseDbService
{
	
	public function __construct(){
		$this->dao		= new SearchKeyDao();
	}
	
	public function addOrUpdate($numIid,$keyword)
	{
		$condition['where']['expression']		= 'num_iid=:num_iid and name=:keyword';
		$condition['where']['value']['num_iid'] = $numIid;
		$condition['where']['value']['keyword'] = $keyword;
		$condition['limit'] = 1;
		$tmp = $this->dao->fetchRows($condition);
		if(!empty($tmp))
		{
                    //待修改
			return $this->dao->update($tmp[0]['id'],array('num'=>$tmp[0]['num']+1));
		}
		else
		{
			return $this->dao->add(array('num_iid'=>$numIid,'name'=>$keyword,'num'=>1,'created'=>date('Y-m-d H:i:s')));
		}
	}
	
	public function getListByNumIid($id)
	{
		$condition['where']['expression']		= 'num_iid=:num_iid';
		$condition['where']['value']['num_iid'] = $id;
		$condition['orderby'] 					= 'num DESC,id DESC';
                $condition['limit'] = 150;
		return $this->dao->fetchRows($condition);
	}
}
?>